package com.master.train.common.exceptionhandler;

import com.master.train.common.exception.BusinessException;
import com.master.train.common.utils.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public R handleBusinessException(BusinessException e) {
        // 记录错误信息
        System.err.println("BusinessException caught: " + e.getMessage());
        // 返回自定义响应
        return R.error().put("message", e.getMessage());
    }
}